package zy.data.food.dto;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import zy.data.food.domain.OrderDetail;
import zy.data.food.enums.OrderStatusEnum;
import zy.data.food.enums.PayStatusEnum;
import zy.data.food.serializer.Date2LongSerializer;
import zy.data.food.util.EnumUtil;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


//该对象用于数据传输
@Data
//在返回的对象中如果不返回为null的属性，使用以下注解，在yml文件中统一配置
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDTO {

    private String orderId;
    private String buyerName;
    private String buyerPhone;
    private String buyerAddress;
    private String buyerOpenid;
    private BigDecimal orderAmount;
    private Integer orderStatus;
    private Integer payStatus;

    @JsonSerialize(using = Date2LongSerializer.class)
    private Date createTime;

    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;

//    List<OrderDetail> orderDetailList = new ArrayList<>(); 给一个初始值
    List<OrderDetail> orderDetailList;

    //返回订单状态的文字描述，不返回到Json中
    @JsonIgnore
    public OrderStatusEnum getOrderStatusEnum(){
       return EnumUtil.getByCode(orderStatus,OrderStatusEnum.class);
    }

    @JsonIgnore
    public PayStatusEnum getPayStatusEnum(){
        return  EnumUtil.getByCode(payStatus,PayStatusEnum.class);
    }
}
